CommonUtils.regNamespace("com.im.pwdchange");

com.im.pwdchange.invoke = function () {

    var client = new com.im.common.ajax();

    function _init() {

        //初始化表单验证
        _initFormValid();
        //
        $("#ensureBtn").click(function () {
            _changePwd();
        });


    }
    function _changePwd(){

        $("#pwdChangeForm").bootstrapValidator('validate');//提交验证
        if (!$("#pwdChangeForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
            return;
        }
           // $("#pwdChangeForm").submit();
        var oldPwd = $("#oldPwdTxt").val();
        var newPwd = $("#oncePwdTxt").val();
        var ensurePwd = $("#ensurePwdTxt").val();

        var result = client.callAsJson("userService/updateStaffPwd", {"operType":"changePwd","oldPwd":oldPwd,"newPwd":newPwd});
        if(result.success){
            toastr.info("操作成功！");
        }else{
            toastr.error("操作失败!"+result.resultMsg);
        }

    };
    function _initFormValid(){

        $("#pwdChangeForm").bootstrapValidator({
            live: 'enabled',
            excluded: [':hidden'],
            feedbackIcons: {valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-loadData'},
            fields: {
                oldPwdTxt : {validators: {notEmpty: {
                            message: '密码不能为空'
                        },
                        stringLength: {
                            min: 8,
                            max: 15,
                            message: '密码必须在8-15个字符之间~'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9]+$/,
                            message: '密码只能由字母、数字组成~'
                        }}}
                ,oncePwdTxt : {validators: {notEmpty: {
                            message: '密码不能为空'
                        },
                        stringLength: {
                            min: 8,
                            max: 15,
                            message: '密码必须在8-15个字符之间~'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9]+$/,
                            message: '密码只能由字母、数字组成~'
                        }, identical: {
                            field: 'ensurePwdTxt',
                            message: '两次输入的密码不相符'
                        }}}
                ,ensurePwdTxt : {validators: {notEmpty: {
                            message: '密码不能为空'
                        },
                        stringLength: {
                            min: 8,
                            max: 15,
                            message: '密码必须在8-15个字符之间~'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9]+$/,
                            message: '密码只能由字母、数字组成~'
                        }, identical: {
                            field: 'oncePwdTxt',
                            message: '两次输入的密码不相符'
                        }}}
            }
        });
    };
    return {
        init: _init
    }

}();

$(function () {
    com.im.pwdchange.invoke.init();
});